import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
import _applyDecoratedDescriptor from "@babel/runtime/helpers/esm/applyDecoratedDescriptor";

var _dec, _dec2, _dec3, _dec4, _dec5, _dec6, _class;

import React, { PureComponent } from 'react';
import { Table } from 'antd';
import { Bind } from 'lodash-decorators';
import { Button as ButtonPermission } from 'components/Permission';
import { createPagination } from 'utils/utils';
import intl from 'utils/intl';
import { statusRender, dateTimeRender, operatorRender } from 'utils/renderer';
/**
 * 消息查询数据展示列表
 * @extends {PureComponent} - React.PureComponent
 * @reactProps {Function} onChange - 分页查询
 * @reactProps {Boolean} loading - 数据加载完成标记
 * @reactProps {Array} dataSource - Table数据源
 * @reactProps {Object} pagination - 分页器
 * @reactProps {Number} pagination.current - 当前页码
 * @reactProps {Number} pagination.pageSize - 分页大小
 * @reactProps {Number} pagination.total - 数据总量
 * @return React.element
 */

var ListTable = (_dec = Bind(), _dec2 = Bind(), _dec3 = Bind(), _dec4 = Bind(), _dec5 = Bind(), _dec6 = Bind(), (_class = /*#__PURE__*/function (_PureComponent) {
  _inherits(ListTable, _PureComponent);

  var _super = _createSuper(ListTable);

  function ListTable() {
    _classCallCheck(this, ListTable);

    return _super.apply(this, arguments);
  }

  _createClass(ListTable, [{
    key: "showRecipientModal",
    value: // 点击收件人查看模态框
    function showRecipientModal(record) {
      var onOpenRecipientModal = this.props.onOpenRecipientModal;
      onOpenRecipientModal(record);
    } // 点击内容查看模态框

  }, {
    key: "showContentModal",
    value: function showContentModal(record) {
      var onOpenContentModal = this.props.onOpenContentModal;
      onOpenContentModal(record);
    } // 点击错误查看模态框

  }, {
    key: "showErrorModal",
    value: function showErrorModal(record) {
      var onOpenErrorModal = this.props.onOpenErrorModal;
      onOpenErrorModal(record);
    }
  }, {
    key: "handleResend",
    value: function handleResend(record) {
      var onResendMessage = this.props.onResendMessage;
      onResendMessage(record);
    }
  }, {
    key: "handleStandardTableChange",
    value: function handleStandardTableChange(pagination) {
      var _this$props = this.props,
          formValues = _this$props.formValues,
          onQueryMessage = _this$props.onQueryMessage;

      var params = _objectSpread({
        page: pagination.current - 1,
        size: pagination.pageSize
      }, formValues);

      onQueryMessage(params);
    }
  }, {
    key: "handleSelectChange",
    value: function handleSelectChange(selectedRowKeys, selectedRows) {
      var _this$props$onSelectC = this.props.onSelectChange,
          onSelectChange = _this$props$onSelectC === void 0 ? function (e) {
        return e;
      } : _this$props$onSelectC;
      onSelectChange(selectedRows, selectedRowKeys);
    }
  }, {
    key: "render",
    value: function render() {
      var _this = this;

      var _this$props2 = this.props,
          _this$props2$messageD = _this$props2.messageData,
          messageData = _this$props2$messageD === void 0 ? {} : _this$props2$messageD,
          loading = _this$props2.loading,
          tenantRoleLevel = _this$props2.tenantRoleLevel,
          path = _this$props2.path,
          resendLoading = _this$props2.resendLoading;
      var rowSelection = {
        onChange: this.handleSelectChange
      };
      var columns = [{
        title: intl.get('entity.tenant.tag').d('租户'),
        dataIndex: 'tenantName',
        width: 120
      }, {
        title: intl.get('cmsg.messageQuery.model.messageQuery.serverCode').d('账号代码'),
        dataIndex: 'serverCode',
        width: 120
      }, {
        title: intl.get('cmsg.common.view.type').d('类型'),
        dataIndex: 'messageTypeMeaning',
        width: 100
      }, {
        title: intl.get('cmsg.messageQuery.model.messageQuery.subject').d('主题'),
        dataIndex: 'subject'
      }, {
        title: intl.get('cmsg.messageQuery.model.messageQuery.sendDate').d('发送时间'),
        dataIndex: 'sendDate',
        width: 150,
        render: dateTimeRender
      }, {
        title: intl.get('cpaas.common.status').d('状态'),
        dataIndex: 'trxStatusCode',
        width: 100,
        render: function render(val, record) {
          return /*#__PURE__*/React.createElement("span", null, statusRender(val, record.trxStatusMeaning));
        }
      }, {
        title: intl.get('cmsg.messageQuery.model.messageQuery.content').d('内容'),
        width: 80,
        key: 'content',
        render: function render(text, record) {
          var operators = [];
          operators.push({
            key: 'view1',
            ele: /*#__PURE__*/React.createElement(ButtonPermission, {
              type: "text",
              permissionList: [{
                code: "".concat(path, ".button.viewContent"),
                type: 'button',
                meaning: '消息查询-查看内容'
              }],
              onClick: function onClick() {
                _this.showContentModal(record);
              }
            }, intl.get('cmsg.messageQuery.view.messageQuery.view').d('查看')),
            len: 2,
            title: intl.get('cmsg.messageQuery.view.messageQuery.view').d('查看')
          });
          return operatorRender(operators);
        }
      }, {
        title: intl.get('cmsg.messageQuery.model.messageQuery.receiver').d('接收人'),
        width: 80,
        key: 'receiver',
        render: function render(text, record) {
          var operators = [];
          operators.push({
            key: 'view2',
            ele: /*#__PURE__*/React.createElement(ButtonPermission, {
              type: "text",
              permissionList: [{
                code: "".concat(path, ".button.viewRecipient"),
                type: 'button',
                meaning: '消息查询-查看接收者'
              }],
              onClick: function onClick() {
                _this.showRecipientModal(record);
              }
            }, intl.get('cmsg.messageQuery.view.messageQuery.view').d('查看')),
            len: 2,
            title: intl.get('cmsg.messageQuery.view.messageQuery.view').d('查看')
          });
          return operatorRender(operators);
        }
      }, {
        title: intl.get('cmsg.messageQuery.model.messageQuery.error').d('错误'),
        width: 80,
        key: 'error',
        render: function render(text, record) {
          var operators = [];

          if (record.trxStatusCode === 'F') {
            operators.push({
              key: 'view3',
              ele: /*#__PURE__*/React.createElement(ButtonPermission, {
                type: "text",
                permissionList: [{
                  code: "".concat(path, ".button.viewError"),
                  type: 'button',
                  meaning: '消息查询-查看错误'
                }],
                onClick: function onClick() {
                  _this.showErrorModal(record);
                }
              }, intl.get('cmsg.messageQuery.view.messageQuery.view').d('查看')),
              len: 2,
              title: intl.get('cmsg.messageQuery.view.messageQuery.view').d('查看')
            });
            return operatorRender(operators);
          }
        }
      }, {
        title: intl.get('cpaas.common.button.action').d('操作'),
        width: 80,
        fixed: 'right',
        key: 'reset',
        render: function render(val, record) {
          var operators = [];

          if (record.trxStatusCode !== 'P') {
            operators.push({
              key: 'resend',
              ele: /*#__PURE__*/React.createElement(ButtonPermission, {
                type: "text",
                permissionList: [{
                  code: "".concat(path, ".button.resend"),
                  type: 'button',
                  meaning: '消息查询-重试'
                }],
                onClick: function onClick() {
                  _this.handleResend(record);
                }
              }, intl.get('cmsg.messageQuery.view.button.resend').d('重试')),
              len: 2,
              title: intl.get('cmsg.messageQuery.view.button.resend').d('重试')
            });
          }

          return operatorRender(operators);
        }
      }].filter(function (col) {
        return tenantRoleLevel ? col.dataIndex !== 'tenantName' : true;
      });
      return /*#__PURE__*/React.createElement(Table, {
        bordered: true,
        rowSelection: rowSelection,
        columns: columns,
        rowKey: "transactionId",
        dataSource: messageData.content || [],
        pagination: createPagination(messageData),
        loading: loading || resendLoading,
        onChange: this.handleStandardTableChange
      });
    }
  }]);

  return ListTable;
}(PureComponent), (_applyDecoratedDescriptor(_class.prototype, "showRecipientModal", [_dec], Object.getOwnPropertyDescriptor(_class.prototype, "showRecipientModal"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "showContentModal", [_dec2], Object.getOwnPropertyDescriptor(_class.prototype, "showContentModal"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "showErrorModal", [_dec3], Object.getOwnPropertyDescriptor(_class.prototype, "showErrorModal"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "handleResend", [_dec4], Object.getOwnPropertyDescriptor(_class.prototype, "handleResend"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "handleStandardTableChange", [_dec5], Object.getOwnPropertyDescriptor(_class.prototype, "handleStandardTableChange"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "handleSelectChange", [_dec6], Object.getOwnPropertyDescriptor(_class.prototype, "handleSelectChange"), _class.prototype)), _class));
export { ListTable as default };